﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using LiveNet.Silverlight;

namespace SilverLightStreamingSample
{
    public partial class Form1 : Form
    {
        LiveMedia m_livemedia;
        MediaFileSet[] sets;
        MediaFile[] files;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            if (string.IsNullOrEmpty(textBox1.Text) ||
                string.IsNullOrEmpty(textBox2.Text))
            {
                MessageBox.Show("Either you have entered no Account ID or Passkey", "Doh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            m_livemedia = new LiveMedia(textBox1.Text, textBox2.Text);
            sets = m_livemedia.ListFileSets();
            foreach (MediaFileSet set in sets)
            {
                listBox1.Items.Add(set.Name);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            int i = listBox1.SelectedIndex;
            MediaFileSet set = sets[i];
            files = set.Files;
            foreach (MediaFile file in files)
            {
                listBox2.Items.Add(file.FileName);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int i = listBox1.SelectedIndex;
            MediaFileSet set = null;
            if (sets != null)
            {
                set = sets[i];
            }
            webBrowser1.Url = set.IFrameUrl;
            
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = listBox2.SelectedIndex;
            MediaFile file = files[i];
            label6.Text = string.Format("Filesize: {0}kb", (file.ByteSize / 1024).ToString());
        }
    }
}
